Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
Sound problem in "for" loop when Player win Javascript

Sound problem. In the "for" loop, a sound has been assigned when the car hits the hitbox of the package to be taken ('pacz'). This is counted as a point. Then the sound play: 'good'. Individually for each collected package. The problem arises when the player collects all 9 packs. The "good" sound then comes on many times at the same time. Is there any way to make the sound of the 9 pack sound 'good' play once at the end of the game?

    var root = this
    var collectedBoxes = 0
    root.mainPacz.gotoAndStop(boxArray[0])
    carCollisionSetup()
    boxCollisionSetup()
    var gameover = false
    function boxCollisionCheck() {
    let carBounds = root.car.getTransformedBounds();
    let infoBox = root.mainPacz
    for (i = 1; i < 10; i++) {
        let boxBounds = root['pacz' + i].getTransformedBounds()
        if (carBounds.intersects(boxBounds) && infoBox.timeline.position == root['pacz' + i].timeline.position) {
            takeAnim(root['pacz' + i])
            collectedBoxes++
            createjs.Sound.play('good')
            console.log('good w pacz')
            if (collectedBoxes < 9) {
                infoBox.gotoAndStop(boxArray[collectedBoxes])
                } else {
                if(!gameover)winFunction()
                console.log(winFunction)
                console.log('wrong pacz else')
            }
        } 
    }
    }
    function winFunction() {
    gameover = true
    console.log("=========WIN========")
    setTimeout (() =>{
        createjs.Sound.play('swietnie')
    },1500)
    setTimeout (() =>{
        root.play();
    },5000)
    stopCycle()
    root.stoper.play()
    //clearInterval(carPosChange)
    //timerTimeMS = 0
}
//ANCHOR Handling losing
function loseFunction() {
    console.log("=========LOSE========")
}

End of game with sounds looks like (These "consol.log" are called a lot of times.): enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda